﻿using RTW.Core.Ioc;
using RTW.Core.Repository;
using RTW.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace RTW.Servers
{
    public class TMsgServer : BaseServers<TMsg>, IAutoInject
    {
        private readonly IRepositoryAsync<TMsg>  repositoryAsync;
        public TMsgServer()
        {
            repositoryAsync = new DapperAsyncRepository<TMsg>();
        }

        /// <summary>
        /// 获取集合数据
        /// </summary>
        /// <returns></returns>
        public async Task<List<TMsg>> GetAllMsg()
        {
            return (await repositoryAsync.GetAllEnumerableAsync()).ToList();
        }

        /// <summary>
        /// 获取最新10条动态数据
        /// </summary>
        /// <returns></returns>
        public async Task<List<TMsg>> GetAllMsgTo()
        {
            return (await repositoryAsync.SqlWithParams("select top(10) * from TMsg where State=0 order by AddTime desc")).ToList();
        }
        /// <summary>
        /// 根据主键进行修改状态
        /// </summary>
        /// <returns></returns>
        public async Task<bool> EditAllMsg(int id)
        {
            return await repositoryAsync.InsertUpdateOrDeleteSqlBool("update TMsg set State =1 where ID="+id+"");
        }
        /// <summary>
         /// 修改状态
         /// </summary>
         /// <returns></returns>
        public async Task<bool> EditAllMsgMan()
        {
            return await repositoryAsync.InsertUpdateOrDeleteSqlBool("update TMsg set State =1");
        }
    }
}
